package com.itheima.IO流.拷贝先读input再写output;

import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;

public class CopyDemo {
    public static void main(String[] args) throws IOException {
       // method1();
        //    method2();
        // methodArray();



    }

    private static void method1() throws IOException {
        //创建输出输入流对象
        FileOutputStream fos = new FileOutputStream("D:\\IdeaProjects\\JavaSE_Code\\b.txt");
        FileInputStream fis = new FileInputStream("D:\\IdeaProjects\\JavaSE_Code\\day622_File&IO流\\a.txt");
        //定义临时变量，作为数据传输的载体‘
        int b;
        //循环读写
        while ((b=fis.read())!=-1){
            fos.write(b);
        }
        //关流，释放资源
        fis.close();
        fos.close();
    }

    private static void method2() throws IOException {
        FileInputStream du = new FileInputStream("D:\\J\\my_project\\test.txt");
        FileOutputStream xie = new FileOutputStream("D:\\IdeaProjects\\BasicCode\\test.txt");

        int b;
        while ((b=du.read())!=-1){
            xie.write(b);
        }
        xie.close();
        du.close();
    }

    private static void methodArray() throws IOException {
        FileInputStream du = new FileInputStream("D:\\J\\my_project\\test.txt");
        FileOutputStream xie = new FileOutputStream("D:\\\\IdeaProjects\\\\BasicCode\\\\test2.txt");

        byte[]bys=new byte[1024];
        int len;

        while ((len=du.read())!=-1){
            xie.write(bys,0,len);
        }
        du.close();
        xie.close();
    }
}
